<style type="text/css" title="currentStyle">
	@import "../media/css/demo_table.css";
	@import "media/css/TableTools.css";
</style>

<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/ZeroClipboard/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		/* You might need to set the sSwfPath! Something like:
		 *   TableToolsInit.sSwfPath = "/media/swf/ZeroClipboard.swf";
		 */
		$('#example').dataTable( {
			"sPaginationType": "full_numbers",
			"sDom": 'T<"clear">lfrtip'
		} );

	} );
</script>
<script language="javascript">
var ajax1=new sack();
function delStudnAttend(index,sid,cid)
{
	t = confirm("You want to delete attendance of "+document.getElementById('studName'+index).innerHTML);
	if(t)
	{
		qry = "delete from tb_student_attendance_info where sai_clientId = "+cid+" and sai_id = "+sid;		
		ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
		//alert(ajax1.requestFile);
		ajax1.onCompletion = function(){resultCount()};
		ajax1.runAJAX();
	}
	
}
function resultCount()
{
  if(ajax1.response > 0 )
  {
  	alert("Data Updated Successfully");
	location.href = '?ch=viewAttendance';
  }
  else
  {
	  alert("Data not Updated");
  }
	
}

function showFormDiv()
{
	if(document.getElementById('formDiv').style.display=='none')
	{
		document.getElementById('formDiv').style.display = 'block';
		document.getElementById('shLink').innerHTML = "Hide Form";
	}
	else
	{
		document.getElementById('formDiv').style.display = 'none';
		if(document.getElementById('shLink'))
		document.getElementById('shLink').innerHTML = "Search";
	}
}
function showPreloader()
{
	document.getElementById('popup_div').innerHTML = '<div id="loading_txt" >Loading...</div>';
	document.frm_map_filter.submit();
}

function hidePreLoader()
{
	document.getElementById('popup_div').innerHTML = '&nbsp;';
}
jQuery(function() {

//$("#time3, #time4").timePicker();
 $("#time3, #time4").timePicker({
  startTime: "12:00 AM", // Using string. Can take string or Date object.
  endTime: "11:59 PM", // Using Date object here.
  show24Hours: false,
  separator: ':',
  step: 1});    
	
// Store time used by duration.
var oldTime = $.timePicker("#time3").getTime();

// Keep the duration between the two inputs.
$("#time3").change(function() {
  if ($("#time4").val()) { // Only update when second input has a value.
	// Calculate duration.
	var duration = ($.timePicker("#time4").getTime() - oldTime);
	var time = $.timePicker("#time3").getTime();
	// Calculate and update the time in the second input.
	$.timePicker("#time4").setTime(new Date(new Date(time.getTime() + duration)));
	oldTime = time;
  }
});
// Validate.
$("#time4").change(function() {
  if($.timePicker("#time3").getTime() > $.timePicker(this).getTime()) {
	$(this).addClass("error");
  }
  else {
	$(this).removeClass("error");
  }
});

});
$(function() {
	$( "#from_date" ).datepicker({
		changeMonth: true,
		changeYear: true,
		maxDate: 0,
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat : "dd-mm-yy"
	});
});
</script>
<div id="formDiv">
<form id="frm_map_filter" name="frm_map_filter" method="post" action="" onsubmit="return validateMapReport();">      	 
<table class="gridform_final" style="width:75%">
<tr><th colspan="6">View Attendance</th></tr>                
    <tr>
    <td width="15%" align="right"><span class="form_text">Date</span></td>
    <td width="35%" align="left">
    <input type="text" name="from_date" id="from_date" readonly="true" size="12" tabindex="2" value="<?php if(isset($_POST[from_date])) echo $_POST[from_date]; else echo date("d-m-Y"); ?>" style="width:140px;"/>
    </td>
    <td width="15%" align="right"><span class="form_text">Morning Time</span></td>
    <td>
    <span><input type="text" name="time3" id="time3" readonly="true" size="7" tabindex="3" value="<?php if($_POST[time3]) echo $_POST[time3]; else echo "12:01 AM";?>" /></span>
    </td>
    <td width="15%" align="right"><span class="form_text">Evening Time</span></td>
    <td>
    <span><input type="text" name="time4" id="time4" readonly="true" size="7" tabindex="5" value="<?php if($_POST[time4]) echo $_POST[time4]; else echo "11:59 PM";?>" /></span>
    </td>
  </tr>
  <tr>
    <td height="33" colspan="6" style="text-align:center">
    <input type="button" name="map_filter_btn"   value="Filter" class="save_btn" tabindex="6"  onclick="showPreloader();"/>
    <input type="hidden" name="map_filter_btn" value="Filter" />
    <input type="button" name="map_cancel_btn" id="map_cancel_btn" value="Reset" class="save_btn" onclick="location.href='index.php?ch=viewAttendance';" tabindex="7" /> 
   </td>
  </tr>
</table>
</form>
</div>
<div id="popup_div" style=" display:block; border:0px;" >

</div>
<div class="listofusers" align="right">&nbsp;<a href="#" class="error_strings" id="shLink" onClick="showFormDiv();">Search</a></div>
<div style="overflow-Y:hidden; padding-top:2%">
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">      
	<thead>
    <tr>
        <th width="15%">Student Name</th>
        <th width="10%">Class</th>
        <th width="7%">Roll No</th>
        <th width="7%">RFID</th>
        <th width="7%">Date</th>
        <th width="10%">In Time </th>
        <th width="10%">Out Time</th>
        <th width="5%">Delete</th>
   </tr>
   </thead>
   <tbody>
   <?php
   if($_POST[from_date] != '' && $_POST[time3] != '' && $_POST[time4] !='')
   {
   	$addCont = "AND sai_date = '".date("Y-m-d",strtotime($_POST[from_date]))."' AND sai_inTime >= '".date("H:i:s",strtotime($_POST[time3]))."' AND sai_outTime <= '".date("H:i:s",strtotime($_POST[time4]))."'";
   }
   else $addCont = "AND sai_date = '".date("Y-m-d")."'";
	$sql = "SELECT * FROM tb_student_info,tb_student_attendance_info WHERE sai_studId = si_id AND si_clientId=".$_SESSION[clientID]." ".$addCont." ORDER BY si_firstName ASC";
	$rows = $db->query($sql);

   if($db->affected_rows > 0)
   {
   $i = 0;
   	while ($fetAttendRecord = $db->fetch_array($rows)) 
	{
	?>
    <tr>
        <td id="studName<?php echo $i;?>"><?php echo ucfirst($fetAttendRecord[si_firstName].' '.$fetAttendRecord[si_lastName]);?></td>
        <td><?php echo ucfirst($fetAttendRecord[si_standard].' '.$fetAttendRecord[si_section]);?></td>
        <td><?php echo $fetAttendRecord[si_rollNo];?> </td>
        <td><?php echo $fetAttendRecord[si_RFIDNo];?> </td>
        <td><?php echo date("d-m-Y",strtotime($fetAttendRecord[sai_date]));?> </td>
        <td><?php echo date('h:i:s A',strtotime($fetAttendRecord[sai_inTime]));?> </td>
        <td><?php if($fetAttendRecord[sai_outTime] !='00:00:00') echo date('h:i:s A',strtotime($fetAttendRecord[sai_outTime])); else echo 'NA';?> </td>
        <td><img src="../../images/delete.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="delStudnAttend('<?php echo $i;?>','<?php echo $fetAttendRecord[sai_id];?>','<?php echo $_SESSION[clientID];?>')" /></td>
   </tr>
   <?php
   $i++;
   	//$avail = 0;
   //}
	}
	}

   ?>
	</tbody>
</table>
</div>

<script type="text/javascript">
showFormDiv();
hidePreLoader();
</script>	

<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtStudId" id="txtStudId" />
</form>
<form name="frmClientType" id="frmClientType" method="post">
	<input type="hidden" name="txtClientType" id="txtClientType" />
</form>
<form name="frmRedirectUser" id="frmRedirectUser" method="post">
	<input type="hidden" name="txtUserId" id="txtUserId" />
    <input type="hidden" name="txtStudId" id="txtStudId" />
    <input type="hidden" name="ResellID" id="ResellID" />
</form>